import { getUserInfoApi } from "@/api/userApi";

export default {
  state: {
    userInfo: JSON.parse(localStorage.getItem("userInfo") || "{}"),
  },
  mutations: {
    // 修改导航栏展开和收起的方法
    setUserInfo(state, res) {
      state.userInfo = res;
      localStorage.setItem("userInfo", JSON.stringify(res));
    },
  },
  actions: {
    // 获取用户信息
    async getUserInfo({ commit }) {
      try {
        const res = await getUserInfoApi();
        console.log(res);
        commit("setUserInfo", res);
      } catch (error) {
        console.log(error);
      }
    },
  },
};
